package org.cos.generation.util.info;

import java.util.ArrayList;
import java.util.List;

import org.cos.generation.util.predict.PredictSet;
import org.cos.generation.util.predict.UnionPredictSet;

public class MethodInfo {

	/** Store initial state of this method. */
	private int initStateIndex;
	
	/** Store return state of this method. */
	private int returnStateIndex;
	
	/** 
	 * Mark weather this method may invoke system method.
	 * 1 means may invoke.
	 * 0 means can't determine.
	 * -1 means must not invoke.
	 */
	private int systemFlag;
	
	/** Store the predict set of parameters. */
	private List<UnionPredictSet> paraPredictList;
	
	/**
	 * Constructor.
	 * @param paraNum
	 * @param initStateIndex
	 * @param returnStateIndex
	 */
	public MethodInfo(int paraNum, int initStateIndex,
			int returnStateIndex) {
		this.initStateIndex = initStateIndex;
		this.returnStateIndex = returnStateIndex;
		paraPredictList = new ArrayList<UnionPredictSet>(paraNum);
		for (int i = 0; i < paraNum; i++) {
			paraPredictList.add(new UnionPredictSet());
		}
	}

	/**
	 * Getter.
	 * @return
	 */
	public int getInitStateIndex() {
		return initStateIndex;
	}

	/**
	 * Getter.
	 * @return
	 */
	public int getReturnStateIndex() {
		return returnStateIndex;
	}

	/**
	 * Getter.
	 * @return
	 */
	public List<UnionPredictSet> getParaPredictSet() {
		return paraPredictList;
	}
	
	/**
	 * Set systemFlag to 1, means this method may invoke system method.
	 */
	public void setSystemRelated() {
		systemFlag = 1;
	}
	
	/**
	 * Set systemFlag to -1, means this method must not invoke system method.
	 */
	public void setSystemUnrelated() {
		systemFlag = -1;
	}
	
	public int getSystemFlag() {
		return systemFlag;
	}
	
	/**
	 * Add new predict set to parameters.
	 * @param newParaPredict
	 */
	public void addParaPredict(List<PredictSet> newParaPredict) {
		int i = 0;
		for (PredictSet newSet : newParaPredict) {
			paraPredictList.get(i++).addChild(newSet);
		}
	}
	
}
